import React from 'react';
class FindCar extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      status: 0,
      data: []
    };
    this.addNeed = this.addNeed.bind(this);
  }
  addNeed(event) {
    let descItem = this.refs['desc'],
      spriceItem = this.refs['sprice'],
      epriceItem = this.refs['eprice'];
    if (descItem.value == '' && spriceItem.value == '' && epriceItem.value == '') {
      alert('您还没有填写信息!');
      return false;
    }
    $.ajax({
      type: "POST",
      url: CBH.apiRoot + "/?g=Api&m=User&a=is_bind_tel",
      data: {
        uid: CBH.UserInfo.id
      },
      dataType: 'jsonp',
      success: function(res) {
        if (res.status) {
          $.ajax({
            type: "POST",
            url: CBH.apiRoot + "/?g=Api&m=NeedCarRegistration&a=add",
            data: {
              uid: CBH.UserInfo.id,
              desc: descItem.value,
              sprice: spriceItem.value,
              eprice: epriceItem.value
            },
            dataType: 'jsonp',
            success: function(result) {
              if (result.status) {
                descItem.value = '';
                spriceItem.value = '';
                epriceItem.value = '';
                alert('提交成功！我们将尽快为您找车');
              } else {
                alert('请稍后再试～！');
              }
            }.bind(this)
          });
        } else {
          blackShadow();
          $('.validate-tel').vhAlign().show();
          $("html, body").animate({
            scrollTop: 0
          }, "600");
        }
      }.bind(this)
    });
    function blackShadow() {
      let ah = $(document).height();
      $('.black-shadow').height(ah).show();
    }
  }
  render() {
    return (
      <div>
        <p className="section-block-title find-car-block">你说车 / 我来找</p>
        <section className="section-block">
          <div className="row">
            <div className="col-xs-12">
              <form className="car-form" action="#">
                <div className="form-group">
                  <input type="text" ref="desc" className="form-control input-lg" placeholder="您想要什么车告诉我们"/>
                  <input type="tel" ref="sprice" className="form-control input-lg" placeholder="您的最低价位"/>
                  <input type="tel" ref="eprice" className="form-control input-lg" placeholder="您的最高价位"/>
                  <button type="button" className="car-submit btn btn-lg btn-block" onClick={this.addNeed}>提交</button>
                </div>
              </form>
            </div>
          </div>
        </section>
      </div>
    )
  }
}
export default FindCar
